<%-- 
    Document   : QLLienhe
    Created on : Dec 29, 2013, 9:52:00 PM
    Author     : THICH HOA DONG TIEN
<%-- 
    Document   : index
    Created on : Dec 3, 2013, 9:42:29 PM
    Author     : Welcome
--%>


<%@page import="bc.entity.Bophan"%>
<%@page import="businesscard.DAO.BophanDAO"%>
<%@page import="bc.entity.Capbac"%>
<%@page import="businesscard.DAO.CapbacDAO"%>
<%@page import="bc.entity.Nhomnganh"%>
<%@page import="businesscard.DAO.NhomnganhDAO"%>
<%@page import="bc.entity.Quanhuyen"%>
<%@page import="java.util.List"%>
<%@page import="businesscard.DAO.QuanhuyenDAO"%>
<%@page import="bc.entity.Thanhpho"%>
<%@page import="businesscard.DAO.ThanhphoDAO"%>
<%@page import="bc.entity.Lienhe"%>
<%@page import="businesscard.DAO.LienheDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="css/style.css" type="text/css"/>
        <link rel="stylesheet" href="css/bocuc.css" type="text/css"/>
        <link rel="stylesheet" href="css/testcss.css" type="text/css"/>
        <link rel="stylesheet" href="css/mystyle.css" type="text/css"/>
        <link rel="stylesheet" href="css/botoncss.css" type="text/css"/>
        <link rel="stylesheet" href="css/cssadmin.css" type="text/css"/>
        <script type="text/javascript" src="jquery/jquery-1.1.3.1.min.js"></script> 
        <script type="text/javascript" src="jquery/jquery-1.4.2.js"></script> 
        <script type="text/javascript" src="jquery/jquery-latest.js"></script>
        <script type="text/javascript" src="jquery/myjquery.js"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script>
            function showform(x) {
                $("#chitietlienhe" + x).fadeIn();

            }
            function closeform(x)
            {
                $("#chitietlienhe" + x).fadeOut();
            }

        </script>

        <script>
            var xmlhttp;
            var x;
            var z;
            function get_nganh(k)
            {
                z = k;

                xmlhttp = GetXmlHttpObject();

                if (xmlhttp == null)
                {
                    alert("Your browser does not support Ajax HTTP");
                    return;
                }
                var q = document.getElementById("nhomnganhlh" + k).value;





                var url = "getNganhAjax.jsp";
                url = url + "?nhom=" + q;

                xmlhttp.onreadystatechange = getOutput;
                xmlhttp.open("GET", url, true);
                xmlhttp.send(null);



            }
            function getOutput()
            {
                if (xmlhttp.readyState == 4 || xmlHttp.readyState == "complete")
                {
                    document.getElementById("selectnganh" + z).innerHTML = xmlhttp.responseText;
                }
            }

            function get_Quanhuyen(y) {
                xmlhttp = GetXmlHttpObject();

                if (xmlhttp == null)
                {
                    alert("Your browser does not support Ajax HTTP");
                    return;
                }
                var thanhpho = document.getElementById("tinhlh" + y).value;

                var url = "getQuanhuyenAjax.jsp";
                url = url + "?thanhpho=" + thanhpho;

                xmlhttp.onreadystatechange = getOutputQuan;
                xmlhttp.open("GET", url, true);
                xmlhttp.send(null);
                x = y;
            }
            function getOutputQuan()
            {
                if (xmlhttp.readyState == 4 || xmlHttp.readyState == "complete")
                {
                    document.getElementById("selecthuyen" + x).innerHTML = xmlhttp.responseText;
                }
            }
            function GetXmlHttpObject()
            {
                if (window.XMLHttpRequest)
                {
                    return new XMLHttpRequest();
                }
                if (window.ActiveXObject)
                {
                    return new ActiveXObject("Microsoft.XMLHTTP");
                }
                return null;
            }
        </script>

        <title>Admin</title>
    </head>
    <body>
        <div class="bodypage">
            <!phan dau cua trang>
            <div class="top">
                <%@include file='header.jsp'%>
            </div>
            <!phan search>
            <div class="khoangcachtrang">
                <div class="searchgroup">

                    <form class="search">
                        <input class="inputsearch" type="text" name="a" value="" onkeyup="showHint(this.value);" />   
                        <input class="btnsearch" type="submit" value="Tìm" name="btnsearch" />
                        <span id="showhint"></span>

                    </form>

                </div>
            </div>

            <!phan giua trang >
            <div class="centerpage">

                <div class="leftsite">
                    <div class="menuweb">
                        <%@include file='menuleft.jsp' %>
                    </div>
                </div>

                <div class="content">

                    <div class="khoangtrang"></div>
                    <table class="danhsach">
                        <thead>
                        <td>XÓA</td>
                        <td class="stt">STT</td>
                        <td>LIÊN HỆ</td>
                        <td>ĐIỆN THOẠI CỐ ĐỊNH</td>
                        <td>ĐIỆN THOẠI DI ĐỘNG</td>
                        <td>FAX</td>
                        <td>ĐỊA CHỈ</td>



                        <td>ACTION</td>

                        </thead>
                        <%
                            LienheDAO lhdao = new LienheDAO();
                            Lienhe[] array = lhdao.getAllLienHe();
                            int stt = 0;
                            for (int i = 0; i < array.length; i++) {
                                int id_lienhe = array[i].getIdLienhe();
                                int id_congty = array[i].getCongty().getIdCongty();
                                String congty = lhdao.getTenCongty(id_congty);
                                String ten = array[i].getTen();
                                String tell = array[i].getSdtcodinh();
                                String mobi = array[i].getSdt();
                                String fax = array[i].getFax();
                                String email1 = array[i].getEmail();
                                String diachi = array[i].getDiachi();
                                String huyen = array[i].getQuanhuyen().getQuanhuyen();
                                String tinh = array[i].getQuanhuyen().getThanhpho().getThanhpho();
                                String capbac = array[i].getCapbac().getCapbac();
                                String bophan = array[i].getBophan().getBophan();
                                String nganh = array[i].getNganh().getNganh();
                                String nhomnganh = array[i].getNganh().getNhomnganh().getNhomnganh();
                                int idtp = array[i].getQuanhuyen().getThanhpho().getIdThanhpho();
                                int idhuyen = array[i].getQuanhuyen().getIdQuanhuyen();
                                int id_nnganh = array[i].getNganh().getNhomnganh().getIdNhomnganh();
                                int id_n = array[i].getNganh().getIdNganh();
                                int id_capbac = array[i].getCapbac().getIdCapbac();
                                int id_bophan = array[i].getBophan().getIdBophan();
                                ThanhphoDAO tpdao = new ThanhphoDAO();
                                Thanhpho[] tp = tpdao.getAllThanhpho();
                                NhomnganhDAO nndao = new NhomnganhDAO();
                                Nhomnganh[] nn = nndao.getAllNhomnganh();
                        %>
                        <tr class="thongtinnv">
                            <td><input type="checkbox" name="chon" value="ON" /></td>
                            <td><div class="stt"><%= stt%></div></td>
                            <td><div class="tenlienhe"><%=ten%></div></td>
                            <td><div class="dtcdlienhe"><%=tell%> </div></td>
                            <td><div class="dtddlienhe"><%=mobi%></div></td>
                            <td><div class="emaillienhe"><%=email1%> </div></td>
                            <td><div class="diachilienhe"><%=diachi%></div></td>




                            <td><form method="POST" action="LienheController" class="hoatdong">
                                    <input type="hidden" name="txtidlienhe" value="<%=id_lienhe%>"/>
                                    <div class="xoanv"><button type="submit" name="action" value="delete">Xóa</button></div>

                                </form>
                                <div id="<%=stt%>" class="chitietlienhe1" onclick="showform(this.id)"><a href="#">Chi tiết</a></div>
                            </td>

                        <div id="chitietlienhe<%=stt%>" class="chitietlienhe2">
                            <div id="<%=stt%>" class="M_closex" itemid="<%=stt%>" onclick="closeform(this.id)"></div>
                            <form action="LienheController" method="POST"id="form<%=stt%>"> 
                                <div class="nhanvienad<%=stt%>">Tên Liên Hệ: <%=ten%></div>
                                <div class="nhanvienad">Số Điện Thoại Cố Định: <input value="<%=tell%>"/> </div>
                                <div class="nhanvienad">Điện Thoại Di động: <input value="<%=mobi%>"/> </div>
                                <div class="nhanvienad">Email: <input value="<%=email1%>"/> </div>
                                <div class="nhanvienad">Địa Chỉ: <input value="<%=diachi%>"/></div>
                                <div class="nhanvienad">Tỉnh/TP: <select id="tinhlh<%= stt%>" name="tinhlh" onchange="get_Quanhuyen(<%= stt%>);">
                                        <option value="<%=idtp%>"><%=tinh%></option>
                                        <%

                                            for (int k = 0; k < tp.length; k++) {
                                                String tentp = tp[k].getThanhpho();
                                                int id_tp = tp[k].getIdThanhpho();

                                        %>
                                        <option value="<%=id_tp%>"><%=tentp%></option>
                                        <%
                                            }
                                        %>
                                    </select> </div>
                                <div class="nhanvienad" id="selecthuyen<%= stt%>">Quận/Huyện: <select id="huyenlh" name="huyenlh">
                                        <option value="<%=idhuyen%>"><%=huyen%></option>

                                    </select> </div>


                                <div class="nhanvienad">Nhóm Ngành: <select id="nhomnganhlh<%= stt%>" name="nhomnganhlh" onchange="get_nganh(<%= stt%>);">
                                        <option value="<%=id_nnganh%>"><%=nhomnganh%></option>
                                        <%

                                            for (int j = 0; j < nn.length; j++) {
                                                int id_nn = nn[j].getIdNhomnganh();
                                                String ten_nn = nn[j].getNhomnganh();
                                        %>

                                        <option value="<%=id_nn%>"><%=ten_nn%></option>
                                        <%
                                            }
                                        %>
                                    </select></div>
                                <div class="nhanvienad" id="selectnganh<%= stt%>">Ngành: <select id="nganhlh" name="nganhlh">
                                        <option value="<%=id_n%>"><%=nganh%></option>

                                    </select></div>
                                <div class="nhanvienad">Cấp Bâc: <select id="capbaclh" name="capbaclh" >
                                        <option value="<%=id_capbac%>"><%=capbac%></option>
                                        <%
                                            CapbacDAO cbdao = new CapbacDAO();
                                            Capbac[] cb = cbdao.getAllCapbac();
                                            for (int x = 0; x < cb.length; x++) {

                                                int id_cb = cb[x].getIdCapbac();
                                                String tencb = cb[x].getCapbac();

                                        %>
                                        <option value="<%=id_cb%>"><%=tencb%></option>
                                        <%
                                            }
                                        %>
                                    </select></div>
                                <div class="nhanvienad">Bộ Phận <select id="bophanlh" name="bophanlh" >
                                        <option value="<%=id_bophan%>"><%=bophan%></option>
                                        <%
                                            BophanDAO bpdao = new BophanDAO();
                                            Bophan[] bp = bpdao.getAllBophan();
                                            for (int h = 0; h < bp.length; h++) {

                                                String ten_bp = bp[h].getBophan();
                                                int id_bp = bp[h].getIdBophan();
                                        %>
                                        <option value="<%=id_bp%>"><%=ten_bp%></option>
                                        <%
                                            }
                                        %>
                                    </select></div>
                                <input type="hidden" name="txtidlienhe" value="<%=id_lienhe%>"/>
                                <div class="updatelh"><input type="submit" value="Sưả thông tin" name="update"/></div>
                            </form>
                        </div>

                        </tr>
                        <%
                                stt++;
                            }

                        %>
                    </table>
                    <div class="khoangtrang"></div>

                </div>


            </div>
            <!phan cuoi trang>
            <div class="footer">
                <div class="footerleft"></div>
                <div class="footerright"></div>
            </div>
        </div>
    </body>
</html>

